﻿/***************************************************************
* NmpStackModalPopUp                                           *
* ----------------                                             *
* E-Mail: nimesh.patel@live.com                                *
* Developer: Nimesh Patel                                      *
***************************************************************/

function ShowNmpStackModalPopUp(strTargetID, strShowDrp) {

    if (strShowDrp == null) {
        strShowDrp = '';
    }
    //strShowDrp  is option to hide drp on page - pass 'true' to hide drp (only for <= IE6)
    if (strStackDivIds == '') {
        var divNmpStackPopUpMain = document.createElement("div");
        divNmpStackPopUpMain.id = 'divNmpStackPopUpMain';
        divNmpStackPopUpMain.className = "divLoader";
        divNmpStackPopUpMain.style.width = document.body.clientWidth + 'px';
        divNmpStackPopUpMain.style.height = document.body.clientHeight + 'px';
        document.body.appendChild(divNmpStackPopUpMain);
    }

    if (strStackDivIds != '') {
        var arrDivIds = strStackDivIds.split(',');
        for (i = 0; i < arrDivIds.length; i++) {
            document.getElementById(arrDivIds[i]).style.zIndex = '990';
        }
        strStackDivIds = strStackDivIds + ',' + strTargetID;
    }
    else {
        strStackDivIds = strTargetID;
    }

    var objTarget = document.getElementById(strTargetID);
    objTarget.style.display = 'block';
    objTarget.style.zIndex = '999';

    SetModalPopUpCenter(strTargetID);
    window.onscroll = function() {
        SetModalPopUpCenter(strTargetID);
    }

    if (strShowDrp == 'true') {
        strStackShowDrp = strShowDrp;
        DrpList = document.getElementsByTagName('select');
        for (var i = 0; i < DrpList.length; i++) {
            if (DrpList[i].style.display == "" || DrpList[i].style.display == "block");
            DrpList[i].style.display = "none";
        }
    }
}

function HideNmpStackModalPopUp() {

    if (strStackDivIds != '') {
        var arrDivIds = strStackDivIds.split(',');
        var lastIndex = arrDivIds.length - 1;
        var strTargetID = arrDivIds[lastIndex];
        var objTarget = document.getElementById(strTargetID);
        objTarget.style.display = 'none';
        strStackDivIds = '';
        for (i = 0; i < arrDivIds.length - 1; i++) {
            if (i != 0) {
                strStackDivIds = strStackDivIds + ',' + arrDivIds[i];
            }
            else {
                strStackDivIds = arrDivIds[i];
            }
        }

        if (strStackDivIds != '') {
            arrDivIds = strStackDivIds.split(',');
            lastIndex = arrDivIds.length - 1;
            strTargetID = arrDivIds[lastIndex];
            var tdNmpStackPopUpMain = document.getElementById('tdNmpStackPopUpMain');
            objTarget = document.getElementById(strTargetID);
            objTarget.style.display = 'block';
            objTarget.style.zIndex = '999';
            SetModalPopUpCenter(strTargetID);
            window.onscroll = function() {
                SetModalPopUpCenter(strTargetID);
            }
        }
    }
    else {
        window.onscroll = null;
    }

    if (strStackDivIds == '') {
        var divNmpStackPopUpMain = document.getElementById('divNmpStackPopUpMain');
        if (divNmpStackPopUpMain != null) {
            document.body.removeChild(divNmpStackPopUpMain);
        }
        if (strStackShowDrp == 'true') {
            DrpList = document.getElementsByTagName('select');
            for (var i = 0; i < DrpList.length; i++) {
                if (DrpList[i].style.display == "" || DrpList[i].style.display == "block");
                DrpList[i].style.display = "";
            }
        }
    }
}

function SetModalPopUpCenter(strTargetID) {
    elem = document.getElementById(strTargetID);
    if (elem == null)
        return;

    //var left = parseInt(elem.offsetWidth / 2);
    var intH = 0, intW = 0;
    if (self.innerHeight) {
        intH = window.innerHeight;
        intW = window.innerWidth;
    }
    else {
        if (document.documentElement && document.documentElement.clientHeight) {
            intH = document.documentElement.clientHeight;
            intW = document.documentElement.clientWidth;
        }
        else {
            if (document.body) {
                intH = document.body.clientHeight;
                intW = document.body.clientWidth;
            }
        }
    }

    //var top = parseInt(elem.offsetHeight / 2);
    var hhh = elem.offsetHeight;
    var www = elem.offsetWidth
    if (intH < elem.offsetHeight && intW < elem.offsetWidth) {
        elem.style.top = '0px';
        elem.style.left = '0px';
        return;
    }

    //elem.style.left = left + 'px';
    var scrOfX = 0, scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }

    if (intH > elem.offsetHeight) {

        var top = (intH == 0) ? 50 : parseInt((intH - elem.offsetHeight) / 2, 10);
        elem.style.top = top + scrOfY + 'px';
    }
    else {
        elem.style.top = '0px';
    }

    if (intW > elem.offsetWidth) {
        var left = (intW == 0) ? 100 : parseInt((intW - elem.offsetWidth) / 2, 10);
        elem.style.left = left + scrOfX + 'px';
    }
    else {
        elem.style.left = '0px';
    }
}

var strStackDivIds = '';
var strStackShowDrp = '';

//window.scrollTo(0, 0);